<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center signUp_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub signUp_fd0_0'>
          <view class='flex flex-wrap align-center signUp_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  signUp_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='signUp_fd0_0_c1_c0'>{{$t('立即报名')}}</text>
          </view>
          <view class='flex flex-wrap align-center justify-end signUp_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
        <view class='flex flex-direction flex-wrap align-stretch signUp_fd1_0'>
          <text class='signUp_fd1_0_c0'>{{$t('学员信息')}}</text>
          <view class='flex flex-wrap align-center justify-between signUp_fd1_0_c1'>
            <text class='signUp_fd1_0_c1_c0'>{{$t('姓名')}}</text>
            <input class='signUp_fd1_0_c1_c1' type="text" :placeholder="$t('请输入')" confirm-type="done" :maxlength="-1"
              placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="true_name" />
          </view>
          <view class='flex flex-wrap align-center justify-between signUp_fd1_0_c1'>
            <text class='signUp_fd1_0_c1_c0'>{{$t('联系方式')}}</text>
            <input class='signUp_fd1_0_c1_c1' type="number" :placeholder="$t('请输入')" confirm-type="done" :maxlength="11"
              placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="mobile" />
          </view>
        </view>
        <!-- <view class='flex flex-wrap align-center signUp_fd1_1'>
        </view> -->
        <!-- <view class='flex flex-direction flex-wrap align-stretch signUp_fd1_0'>
          <text class='signUp_fd1_2_c0'>{{$t('付款信息')}}</text>
          <view class='flex flex-wrap align-center signUp_fd1_0_c1'>
            <text class='signUp_fd1_2_c1_c0'>{{$t('报名费')}}：</text>
            <text class='signUp_fd1_2_c1_c1'>$</text>
            <text class='signUp_fd1_2_c1_c2'>{{money}}</text>
          </view>
          <view class='flex flex-wrap align-center justify-end signUp_fd1_2_c2'>
            <text class='signUp_fd1_2_c2_c0'>{{$t('合计')}}：</text>
            <text class='signUp_fd1_2_c2_c1'>$</text>
            <text class=' signUp_fd1_2_c2_c2'>
              <text class=' signUp_price1_fd1_2_c2_c2'>{{ money | frontPrice }}</text>
              <text class=' signUp_price2_fd1_2_c2_c2'>{{ money | laterPrice }}</text>
            </text>
          </view>
        </view> -->
        <!-- <view class='flex flex-wrap align-center signUp_fd1_1'>
        </view> -->
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <!-- <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout signUp_flex_2">
        <view class='flex flex-wrap align-center'>
          <text class='signUp_fd2_0_c0'>{{$t('选择支付方式')}}</text>
        </view>
        <benben-select-diy ref="showSelectPopup1703169762016" class-name='flex flex-direction align-stretch flex'
          :items.sync="payment" v-model="pay_id" :label.sync="pay_name" default-type="method_name"
          default-label="method_name" :allow-cancel='false' type="radio" :disabled='false'>
          <template v-for='(item,key0) in payment'>
            <view v-if="item.isSelected" class='flex justify-between flex signUp_fd2_1_c0' :key="key0"
              @tap="$refs.showSelectPopup1703169762016.tapHandle(key0)">
              <view class='flex flex-wrap align-center'>
                <image class='signUp_fd2_1_c0_c0_c0' mode="aspectFit" :src='item.thumb'></image>
                <text class='signUp_fd2_1_c0_c0_c1'>{{item.method_name}}</text>
              </view>
              <image class='signUp_fd2_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
            </view>
            <view v-else class='flex justify-between flex signUp_fd2_1_c0' :key="key0"
              @tap="$refs.showSelectPopup1703169762016.tapHandle(key0)">
              <view class='flex flex-wrap align-center'>
                <image class='signUp_fd2_1_c0_c0_c0' mode="aspectFit" :src='item.thumb'></image>
                <text class='signUp_fd2_1_c0_c0_c1'>{{item.method_name}}</text>
              </view>
              <image class='signUp_fd2_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
            </view>
          </template></benben-select-diy>
      </view> -->

      <!---flex布局flex布局结束-->
      <view
        class="flex flex-direction flex-wrap align-stretch justify-center benben-position-layout flex signUp_flex_3">
        <view class='flex flex-wrap align-center justify-between flex-sub signUp_fd3_0'>
          <view class='flex flex-wrap align-center'>
            <!--  <text class='signUp_fd3_0_c0_c0'>{{$t('报名费：')}}</text>
            <text class='signUp_fd3_0_c0_c1'>￥</text>
            <text class=' signUp_fd3_0_c0_c2'>
              <text class=' signUp_price1_fd3_0_c0_c2'>{{ money | frontPrice }}</text>
              <text class=' signUp_price2_fd3_0_c0_c2'>{{ money | laterPrice }}</text>
            </text> -->
          </view>
          <view class='flex flex-wrap align-center'>
            <button class='signUp_fd3_0_c1_c0' @tap.stop="confirmPaymentFunc()">{{$t('立即报名')}}</button>
          </view>
        </view>

      </view>
      <view :style="{height: '106rpx'}"></view>


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "true_name": "",
        "mobile": "",
        "dataInfo": [],
        "payment": [],
        "pay_id": "",
        "order": "",
        "id": "",
        "money": "",
        pay_name: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        order,
        id,
        money
      } = options
      if (order !== undefined) this.order = order
      if (id !== undefined) this.id = id
      if (money !== undefined) this.money = money
      this.getPaymentFunc()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //获取支付方式
      async getPaymentFunc() {
        //请求方法
        //数据验证

        let datapayment = await this.$api.get(global.apiUrls.post62fc4f70a9d44, {

        });

        if (datapayment.data.code != 1) {
          this.$message.info(datapayment.data.msg);
          return
        }
        let infopayment = datapayment.data;
        this.payment = infopayment.data

      },
      //确认支付
      async confirmPaymentFunc() {
        if (!validate(this.true_name, 'require')) {
          this.$message.info(global.i18n.t('姓名不能为空'));
          return false;
        }
        if (!validate(this.mobile, 'require')) {
          this.$message.info(global.i18n.t('联系方式不能为空'));
          return false;
        }
        // if (!validate(this.mobile, 'phone')) {
        //   this.$message.info(global.i18n.t('请输入正确的联系方式'));
        //   return false;
        // }
        // if (!validate(this.pay_id, 'require')) {
        //   this.$message.info(global.i18n.t('请选择支付方式'));
        //   return false;
        // }
        //请求方法
        //数据验证

        let datadataInfo = await this.$api.dbPost(global.apiUrls.post656005028e4eb, {
          true_name: this.true_name,
          mobile: this.mobile,
          money: this.money,
          events_id: this.id,
          pay_type: this.pay_id
        });

        if (datadataInfo.data.code != 1) {
          this.$message.info(datadataInfo.data.msg);
          return
        }
        let infodataInfo = datadataInfo.data;
        this.dataInfo = infodataInfo.data
        this.$message.info(datadataInfo.data.msg)
        setTimeout(res => {
          uni.navigateBack({})
        }, 500)

        // this.getPay(this.dataInfo.order_sn)
        // this.$urouter.navigateTo(
        //   `/pages/shouye/paymentSuccessful/paymentSuccessful?order=${this.dataInfo.order_sn}&pay=${this.pay_name}`);

      },
      getPay(order_sn) {
        uni.showLoading({
          icon: 'loading',
          title: '数据正在提交中,请勿连续点击'
        })
        this.$api.post(global.apiUrls.post659b9ab8e7217, {
          order_sn: order_sn,
          pay_type: this.pay_id
        }).then(res => {
          if (res.data.code == 1) {
            if (res.data.data.pay_type == '零元支付') {
              // 跳转支付成功
              this.$urouter.redirectTo(
                // `/pages/shouye/paymentSuccessful/paymentSuccessful?order=${this.dataInfo.order_sn}&pay=${this.pay_name}`
                `/pages/wode/myActivities/myActivities`
              );
              uni.hideLoading()
              return;
            }
            if (res.data.data.pay_type == 'Stripe') {
              this.$urouter.navigateTo(`/pages/benben-built-in/web-view/web-view?webPath=${res.data.data.url}`);
              uni.hideLoading()
            } else {
              let datas = res.data.data
              uni.requestPayment({
                provider: 'wxpay',
                // #ifdef APP-PLUS
                orderInfo: datas,
                // #endif
                success: (e) => {
                  console.log('success', e)
                  if (e.errMsg == 'requestPayment:ok') {
                    this.$urouter.redirectTo(
                      // `/pages/shouye/paymentSuccessful/paymentSuccessful?order=${this.dataInfo.order_sn}&pay=${this.pay_name}`
                      `/pages/wode/myActivities/myActivities`
                    );
                  }
                },
                fail: (e) => {
                  console.log('e.errMsg', e)
                  // #ifdef APP-PLUS
                  let failMsg = 'requestPayment:fail canceled';
                  // #endif
                  // #ifndef APP-PLUS
                  let failMsg = 'requestPayment:fail cancel';
                  // #endif
                  if (e.errMsg == failMsg) {
                    this.$message.info(this.$t('取消支付'));
                  } else {
                    this.$message.info(this.$t("支付失败,请稍后重试1"));
                  }
                  reject(e)
                },
                complete: () => {}
              });
              uni.hideLoading()
            }

          }
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(247, 243, 237, 1);
    background-size: 100% auto;
  }

  .signUp_flex_0 {
    border-bottom: 1px solid #eee;
    background: rgba(247, 243, 237, 1);
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .signUp_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .signUp_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .signUp_fd0_0_c0 {
    width: 120rpx;
  }

  .signUp_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .signUp_price2_fd1_2_c2_c2 {
    font-size: 20rpx;
  }

  .signUp_price1_fd1_2_c2_c2 {
    font-size: 32rpx;
  }

  .signUp_fd1_2_c2_c2 {
    color: rgba(251, 42, 37, 1);
    font-weight: 600;
  }

  .signUp_fd1_2_c2_c1 {
    color: #FB2A25;
    font-size: 20rpx;
    font-weight: 700;
    line-height: 36rpx;
  }

  .signUp_fd1_2_c2_c0 {
    color: #666666;
    font-size: 24rpx;
    font-weight: 500;
    line-height: 42rpx;
    margin: 0rpx 20rpx 0rpx 0rpx;
  }

  .signUp_fd1_2_c2 {
    margin: 35rpx 0rpx 0rpx 0rpx;
  }

  .signUp_fd1_2_c1_c2 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 42rpx;
  }

  .signUp_fd1_2_c1_c1 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 42rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .signUp_fd1_2_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 42rpx;
  }

  .signUp_fd1_2_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 42rpx;
  }

  .signUp_fd1_1 {
    background: rgba(235, 228, 217, 1);
    margin: 32rpx 32rpx 0rpx 32rpx;
    border-radius: 10rpx;
    height: 20rpx;
    background-size: 100% auto;
  }

  .signUp_fd1_0_c1_c1 {
    text-align: right;
    font-size: 32rpx;
    color: #333;
  }

  .signUp_fd1_0_c1_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 42rpx;
  }

  .signUp_fd1_0_c1 {
    margin: 24rpx 0rpx 0rpx 0rpx;
  }

  .signUp_fd1_0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .signUp_fd1_0 {
    margin: 32rpx 32rpx 0rpx 32rpx;
  }

  .signUp_flex_2 {
    margin: 32rpx 0rpx 0rpx 0rpx;
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .signUp_fd2_1_c0_c1 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .signUp_fd2_1_c0_c0_c1 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 53rpx;
  }

  .signUp_fd2_1_c0_c0_c0 {
    width: 52rpx;
    height: 52rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .signUp_fd2_1_c0 {
    border-bottom: 1px solid rgba(232, 229, 216, 1);
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .signUp_fd2_0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 56rpx;
  }

  .signUp_flex_3 {
    background: rgba(255, 253, 250, 1);
    width: 750rpx;
    height: 106rpx;
    overflow: hidden;
    z-index: 10;
    bottom: calc(0rpx + var(--window-bottom));
    background-size: 100% auto;
  }

  .signUp_fd3_0_c1_c0 {
    background: rgba(145, 47, 34, 1);
    border-radius: 40rpx;
    width: 234rpx;
    line-height: 80rpx;
    font-size: 32rpx;
    color: #fff;
  }

  .signUp_price2_fd3_0_c0_c2 {
    font-size: 20rpx;
  }

  .signUp_price1_fd3_0_c0_c2 {
    font-size: 32rpx;
  }

  .signUp_fd3_0_c0_c2 {
    color: rgba(145, 47, 34, 1);
    font-weight: 600;
  }

  .signUp_fd3_0_c0_c1 {
    color: #912F22;
    font-size: 20rpx;
    font-weight: 700;
    line-height: 36rpx;
  }

  .signUp_fd3_0_c0_c0 {
    color: #1A1A1A;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .signUp_fd3_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }
</style>
